package com.nineclock.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nineclock.system.pojo.SysCompany;
import com.nineclock.system.pojo.SysCompanyUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Mapper
public interface SysCompanyMapper extends BaseMapper<SysCompany> {

    @Select("select * from sys_company_user where id = (select company_user_id from sys_company_user_role where role_id = " +
            "(select id from sys_role where company_id = #{companyId} and role_name = 'ROLE_ADMIN_SYS') and company_id = #{companyId})")
    public SysCompanyUser getCurrentAdmin(Long companyId);

    @Select("select * from sys_company where id in (select company_id from sys_company_user where user_id = #{userId})")
    List<SysCompany> queryCompanyListByUserId(Long userId);
}
